package ru.ognick.coachsystem.core;

import java.util.ArrayList;

import ru.ognick.coachsystem.R;
import ru.ognick.coachsystem.common.Training;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.ListView;

public class CoreActivity extends Activity {
	public final String TAG = getClass().getSimpleName();
	private Training training;
	private ListView listView;
	private CoreExerciseAdapter exerciseAdapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.core);
        
        listView = (ListView) findViewById(R.id.listViewEditor);

        exerciseAdapter = new CoreExerciseAdapter(this, 
        		                                  android.R.layout.simple_list_item_1,
        		                                  new ArrayList<CoreExerciseView>());
        
        training = (Training) getIntent().getSerializableExtra("TRAINING");
        
        exerciseAdapter.loadData(training);
        listView.setAdapter(exerciseAdapter);
        
        if (savedInstanceState != null) {
			SavedState savedStates = 
        		(SavedState) savedInstanceState.getSerializable("SAVED_STATES");
        	exerciseAdapter.setSavedStates(savedStates);
        }
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
//            moveTaskToBack(false);
//            return true;
//        	training.save();
        }
        return super.onKeyDown(keyCode, event);
    }
    
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////STATE////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////	
	@Override
	public void onSaveInstanceState(Bundle savedInstanceState) {
		SavedState savedStates = exerciseAdapter.getSavedStates();
		savedInstanceState.putSerializable("SAVED_STATES", savedStates);
		super.onSaveInstanceState(savedInstanceState);
	}
}
